package com.shylock.as.api.controller;

import com.shylock.as.service.intf.UserService;
import com.shylock.common.bo.UserBo;
import com.shylock.common.bo.UserCodeBo;
import com.shylock.common.config.SystemConfig;
import com.shylock.common.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("api/user")
@Api(value = "登录认证模块接口",tags = "登录认证模块接口")
//@CrossOrigin
public class UserController {
    
    @Autowired 
    private UserService service;
    @ApiOperation(value = "注册账号",notes = "注册账号")
    @PostMapping("register")
    public R add(@RequestBody UserBo bo, HttpServletRequest request){
        return service.register(bo,request.getRemoteAddr());
    }
    @ApiOperation(value = "校验手机号是否存在",notes = "校验手机号是否存在")
    @GetMapping("checkphone")
    public R checkphone(String phone){
        return service.checkPhone(phone);
    }
    
    @ApiOperation(value = "手机号密码登录",notes = "手机号密码登录")
    @PostMapping("login")
    public R login(@RequestBody UserBo bo,HttpServletRequest request){
        return service.loginPassword(bo,request.getRemoteAddr());
    }
    
    @ApiOperation(value = "手机号验证码登录",notes = "手机号验证码登录")
    @PostMapping("logincode")
    public R loginCode(@RequestBody UserCodeBo bo, HttpServletRequest request){
        return service.loginCode(bo,request.getRemoteAddr());
    }
    @ApiOperation(value = "验证找回密码的验证码",notes = "验证找回密码的验证码")
    @PostMapping("findcode")
    public R findCode(@RequestBody UserCodeBo bo, HttpServletRequest request){
        return service.findPassword(bo,request.getRemoteAddr());
    }
    @ApiOperation(value = "找回密码进行密码的修改",notes = "找回密码进行密码的修改")
    @PostMapping("findupdatepass")
    public R findupdatepass(@RequestBody UserBo bo, HttpServletRequest request){
        return service.updatePassword(bo,request.getRemoteAddr());
    }
    @ApiOperation(value = "校验令牌",notes = "校验令牌")
    @GetMapping("checktoken")
    public R checkToken(HttpServletRequest request){
        return service.checkToken(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation(value = "通过令牌获取用户信息",notes = "通过令牌获取用户信息")
    @GetMapping("getuserinfo")
    public R getuserInfo(HttpServletRequest request){
        return service.queryUserInfo(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation(value = "注销登录，退出",notes = "注销登录，退出")
    @GetMapping("loginout")
    public R loginOut(HttpServletRequest request){
        return service.loginOut(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    
    
    
}
